In [4]:

import pandas as pd

In [18]:

btc = pd.read_csv('coin_bitcoin.csv')btc

Out[18]:

 

SNo

Name

Symbol

Date

High

Low

Open

Close

Volume

Marketcap

0

1

Bitcoin

BTC

2013-04-29 23:59:59

147.488007

134.000000

134.444000

144.539993

0.000000e+00

1.603769e+09

1

2

Bitcoin

BTC

2013-04-30 23:59:59

146.929993

134.050003

144.000000

139.000000

0.000000e+00

1.542813e+09

2

3

Bitcoin

BTC

2013-05-01 23:59:59

139.889999

107.720001

139.000000

116.989998

0.000000e+00

1.298955e+09

3

4

Bitcoin

BTC

2013-05-02 23:59:59

125.599998

92.281898

116.379997

105.209999

0.000000e+00

1.168517e+09

4

5

Bitcoin

BTC

2013-05-03 23:59:59

108.127998

79.099998

106.250000

97.750000

0.000000e+00

1.085995e+09

...

...

...

...

...

...

...

...

...

...

...

2986

2987

Bitcoin

BTC

2021-07-02 23:59:59

33939.588699

32770.680780

33549.600177

33897.048590

3.872897e+10

6.354508e+11

2987

2988

Bitcoin

BTC

2021-07-03 23:59:59

34909.259899

33402.696536

33854.421362

34668.548402

2.438396e+10

6.499397e+11

2988

2989

Bitcoin

BTC

2021-07-04 23:59:59

35937.567147

34396.477458

34665.564866

35287.779766

2.492431e+10

6.615748e+11

2989

2990

Bitcoin

BTC

2021-07-05 23:59:59

35284.344430

33213.661034

35284.344430

33746.002456

2.672155e+10

6.326962e+11

2990

2991

Bitcoin

BTC

2021-07-06 23:59:59

35038.536363

33599.916169

33723.509655

34235.193451

2.650126e+10

6.418992e+11

2991 rows × 10 columns

In [4]:

btc.info()

<class 'pandas.core.frame.DataFrame'>

RangeIndex: 2991 entries, 0 to 2990

Data columns (total 10 columns):

 #   Column     Non-Null Count  Dtype  

---  ------     --------------  -----  

 0   SNo        2991 non-null   int64  

 1   Name       2991 non-null   object

 2   Symbol     2991 non-null   object

 3   Date       2991 non-null   object

 4   High       2991 non-null   float64

 5   Low        2991 non-null   float64

 6   Open       2991 non-null   float64

 7   Close      2991 non-null   float64

 8   Volume     2991 non-null   float64

 9   Marketcap  2991 non-null   float64

dtypes: float64(6), int64(1), object(3)

memory usage: 233.8+ KB

In [28]:

btc.set_index('High', inplace=False)

Out[28]:

 

SNo

Name

Symbol

Low

Open

Close

Volume

Marketcap

High

 

 

 

 

 

 

 

 

147.488007

1

Bitcoin

BTC

134.000000

134.444000

144.539993

0.000000e+00

1.603769e+09

146.929993

2

Bitcoin

BTC

134.050003

144.000000

139.000000

0.000000e+00

1.542813e+09

139.889999

3

Bitcoin

BTC

107.720001

139.000000

116.989998

0.000000e+00

1.298955e+09

125.599998

4

Bitcoin

BTC

92.281898

116.379997

105.209999

0.000000e+00

1.168517e+09

108.127998

5

Bitcoin

BTC

79.099998

106.250000

97.750000

0.000000e+00

1.085995e+09

...

...

...

...

...

...

...

...

...

33939.588699

2987

Bitcoin

BTC

32770.680780

33549.600177

33897.048590

3.872897e+10

6.354508e+11

34909.259899

2988

Bitcoin

BTC

33402.696536

33854.421362

34668.548402

2.438396e+10

6.499397e+11

35937.567147

2989

Bitcoin

BTC

34396.477458

34665.564866

35287.779766

2.492431e+10

6.615748e+11

35284.344430

2990

Bitcoin

BTC

33213.661034

35284.344430

33746.002456

2.672155e+10

6.326962e+11

35038.536363

2991

Bitcoin

BTC

33599.916169

33723.509655

34235.193451

2.650126e+10

6.418992e+11

2991 rows × 8 columns

In [29]:

btc.Open

Out[29]:

Date

2013-04-29 23:59:59      134.444000

2013-04-30 23:59:59      144.000000

2013-05-01 23:59:59      139.000000

2013-05-02 23:59:59      116.379997

2013-05-03 23:59:59      106.250000

                           ...     

2021-07-02 23:59:59    33549.600177

2021-07-03 23:59:59    33854.421362

2021-07-04 23:59:59    34665.564866

2021-07-05 23:59:59    35284.344430

2021-07-06 23:59:59    33723.509655

Name: Open, Length: 2991, dtype: float64

In [30]:

btc.High.plot()

Out[30]:

<Axes: xlabel='Date'>

 

In [32]:

btc = pd.read_csv('coin_bitcoin.csv')btc.High

Out[32]:

0         147.488007

1         146.929993

2         139.889999

3         125.599998

4         108.127998

            ...     

2986    33939.588699

2987    34909.259899

2988    35937.567147

2989    35284.344430

2990    35038.536363

Name: High, Length: 2991, dtype: float64

In [34]:

btc.High.plot()

Out[34]:

<Axes: >

 

In [13]:

countries = pd.read_csv('world-happiness-report-2021.csv')countries

Out[13]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

0

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

1

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

3

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

4

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

144

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

145

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

146

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

147

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

148

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 20 columns

In [230]:

countries[['Healthy life expectancy']]

Out[230]:

 

Healthy life expectancy

0

72.000

1

72.700

2

74.400

3

73.000

4

72.400

...

...

144

48.700

145

59.269

146

61.400

147

56.201

148

52.493

149 rows × 1 columns

In [15]:

countries.set_index('Country name')

Out[15]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 19 columns

In [24]:

countries['Healthy life expectancy'].head(25).plot(kind = 'barh', color = 'magenta')

Out[24]:

<Axes: >

 

In [28]:

countries = pd.read_csv('world-happiness-report-2021.csv', index_col = 'Country name')countries

Out[28]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 19 columns

In [32]:

countries = pd.read_csv('world-happiness-report-2021.csv')countries

Out[32]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

0

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

1

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

3

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

4

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

144

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

145

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

146

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

147

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

148

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 20 columns

In [35]:

countries.sort_values('Healthy life expectancy')

Out[35]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

127

Chad

Sub-Saharan Africa

4.355

0.094

4.540

4.171

7.364

0.619

48.478

0.579

0.041

0.807

2.43

0.255

0.353

0.000

0.240

0.215

0.084

3.209

144

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

115

Nigeria

Sub-Saharan Africa

4.759

0.052

4.861

4.658

8.533

0.740

50.102

0.737

0.037

0.878

2.43

0.663

0.625

0.051

0.433

0.212

0.039

2.736

84

Ivory Coast

Sub-Saharan Africa

5.306

0.078

5.460

5.152

8.551

0.644

50.114

0.741

-0.016

0.794

2.43

0.669

0.409

0.052

0.438

0.177

0.092

3.469

129

Swaziland

Sub-Saharan Africa

4.308

0.071

4.448

4.168

9.065

0.770

50.833

0.647

-0.185

0.708

2.43

0.849

0.693

0.074

0.323

0.067

0.147

2.155

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

26

Spain

Western Europe

6.491

0.042

6.574

6.408

10.571

0.932

74.700

0.761

-0.081

0.745

2.43

1.375

1.057

0.826

0.462

0.135

0.124

2.513

55

Japan

East Asia

5.940

0.040

6.020

5.861

10.611

0.884

75.100

0.796

-0.258

0.638

2.43

1.389

0.949

0.838

0.504

0.020

0.192

2.048

76

Hong Kong S.A.R. of China

East Asia

5.477

0.049

5.573

5.380

11.000

0.836

76.820

0.717

0.067

0.403

2.43

1.525

0.841

0.893

0.408

0.232

0.342

1.236

31

Singapore

Southeast Asia

6.377

0.043

6.460

6.293

11.488

0.915

76.953

0.927

-0.018

0.082

2.43

1.695

1.019

0.897

0.664

0.176

0.547

1.379

149 rows × 20 columns

In [36]:

countries.sort_values('Healthy life expectancy',ascending = False)

Out[36]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

31

Singapore

Southeast Asia

6.377

0.043

6.460

6.293

11.488

0.915

76.953

0.927

-0.018

0.082

2.43

1.695

1.019

0.897

0.664

0.176

0.547

1.379

76

Hong Kong S.A.R. of China

East Asia

5.477

0.049

5.573

5.380

11.000

0.836

76.820

0.717

0.067

0.403

2.43

1.525

0.841

0.893

0.408

0.232

0.342

1.236

55

Japan

East Asia

5.940

0.040

6.020

5.861

10.611

0.884

75.100

0.796

-0.258

0.638

2.43

1.389

0.949

0.838

0.504

0.020

0.192

2.048

26

Spain

Western Europe

6.491

0.042

6.574

6.408

10.571

0.932

74.700

0.761

-0.081

0.745

2.43

1.375

1.057

0.826

0.462

0.135

0.124

2.513

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

129

Swaziland

Sub-Saharan Africa

4.308

0.071

4.448

4.168

9.065

0.770

50.833

0.647

-0.185

0.708

2.43

0.849

0.693

0.074

0.323

0.067

0.147

2.155

84

Ivory Coast

Sub-Saharan Africa

5.306

0.078

5.460

5.152

8.551

0.644

50.114

0.741

-0.016

0.794

2.43

0.669

0.409

0.052

0.438

0.177

0.092

3.469

115

Nigeria

Sub-Saharan Africa

4.759

0.052

4.861

4.658

8.533

0.740

50.102

0.737

0.037

0.878

2.43

0.663

0.625

0.051

0.433

0.212

0.039

2.736

144

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

127

Chad

Sub-Saharan Africa

4.355

0.094

4.540

4.171

7.364

0.619

48.478

0.579

0.041

0.807

2.43

0.255

0.353

0.000

0.240

0.215

0.084

3.209

149 rows × 20 columns

In [38]:

houses = pd.read_csv('kc_house_data.csv')titanic = pd.read_csv('titanic.csv')

In [41]:

houses.sort_values(['price','bedrooms','bathrooms'], ascending = False)

Out[41]:

 

id

date

price

bedrooms

bathrooms

sqft_living

sqft_lot

floors

waterfront

view

...

grade

sqft_above

sqft_basement

yr_built

yr_renovated

zipcode

lat

long

sqft_living15

sqft_lot15

7252

6762700020

20141013T000000

7700000.0

6

8.00

12050

27600

2.5

0

3

...

13

8570

3480

1910

1987

98102

47.6298

-122.323

3940

8800

3914

9808700762

20140611T000000

7062500.0

5

4.50

10040

37325

2.0

1

2

...

11

7680

2360

1940

2001

98004

47.6500

-122.214

3930

25449

9254

9208900037

20140919T000000

6885000.0

6

7.75

9890

31374

2.0

0

4

...

13

8860

1030

2001

0

98039

47.6305

-122.240

4540

42730

4411

2470100110

20140804T000000

5570000.0

5

5.75

9200

35069

2.0

0

0

...

13

6200

3000

2001

0

98039

47.6289

-122.233

3560

24345

1448

8907500070

20150413T000000

5350000.0

5

5.00

8000

23985

2.0

0

4

...

12

6720

1280

2009

0

98004

47.6232

-122.220

4600

21750

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

8274

3883800011

20141105T000000

82000.0

3

1.00

860

10426

1.0

0

0

...

6

860

0

1954

0

98146

47.4987

-122.341

1140

11250

16198

3028200080

20150324T000000

81000.0

2

1.00

730

9975

1.0

0

0

...

5

730

0

1943

0

98168

47.4808

-122.315

860

9000

465

8658300340

20140523T000000

80000.0

1

0.75

430

5050

1.0

0

0

...

4

430

0

1912

0

98014

47.6499

-121.909

1200

7500

15293

40000362

20140506T000000

78000.0

2

1.00

780

16344

1.0

0

0

...

5

780

0

1942

0

98168

47.4739

-122.280

1700

10387

1149

3421079032

20150217T000000

75000.0

1

0.00

670

43377

1.0

0

0

...

3

670

0

1966

0

98022

47.2638

-121.906

1160

42882

21613 rows × 21 columns

In [42]:

titanic.head(10)

Out[42]:

 

pclass

survived

name

sex

age

sibsp

parch

ticket

fare

cabin

embarked

boat

body

home.dest

0

1

1

Allen, Miss. Elisabeth Walton

female

29

0

0

24160

211.3375

B5

S

2

?

St Louis, MO

1

1

1

Allison, Master. Hudson Trevor

male

0.9167

1

2

113781

151.55

C22 C26

S

11

?

Montreal, PQ / Chesterville, ON

2

1

0

Allison, Miss. Helen Loraine

female

2

1

2

113781

151.55

C22 C26

S

?

?

Montreal, PQ / Chesterville, ON

3

1

0

Allison, Mr. Hudson Joshua Creighton

male

30

1

2

113781

151.55

C22 C26

S

?

135

Montreal, PQ / Chesterville, ON

4

1

0

Allison, Mrs. Hudson J C (Bessie Waldo Daniels)

female

25

1

2

113781

151.55

C22 C26

S

?

?

Montreal, PQ / Chesterville, ON

5

1

1

Anderson, Mr. Harry

male

48

0

0

19952

26.55

E12

S

3

?

New York, NY

6

1

1

Andrews, Miss. Kornelia Theodosia

female

63

1

0

13502

77.9583

D7

S

10

?

Hudson, NY

7

1

0

Andrews, Mr. Thomas Jr

male

39

0

0

112050

0

A36

S

?

?

Belfast, NI

8

1

1

Appleton, Mrs. Edward Dale (Charlotte Lamson)

female

53

2

0

11769

51.4792

C101

S

D

?

Bayside, Queens, NY

9

1

0

Artagaveytia, Mr. Ramon

male

71

0

0

PC 17609

49.5042

?

C

?

22

Montevideo, Uruguay

In [44]:

titanic.sort_values('name', key = lambda col: col.str.lower()).head(20)

Out[44]:

 

pclass

survived

name

sex

age

sibsp

parch

ticket

fare

cabin

embarked

boat

body

home.dest

600

3

0

Abbing, Mr. Anthony

male

42

0

0

C.A. 5547

7.55

?

S

?

?

?

601

3

0

Abbott, Master. Eugene Joseph

male

13

0

2

C.A. 2673

20.25

?

S

?

?

East Providence, RI

602

3

0

Abbott, Mr. Rossmore Edward

male

16

1

1

C.A. 2673

20.25

?

S

?

190

East Providence, RI

603

3

1

Abbott, Mrs. Stanton (Rosa Hunt)

female

35

1

1

C.A. 2673

20.25

?

S

A

?

East Providence, RI

604

3

1

Abelseth, Miss. Karen Marie

female

16

0

0

348125

7.65

?

S

16

?

Norway Los Angeles, CA

605

3

1

Abelseth, Mr. Olaus Jorgensen

male

25

0

0

348122

7.65

F G63

S

A

?

Perkins County, SD

323

2

0

Abelson, Mr. Samuel

male

30

1

0

P/PP 3381

24

?

C

?

?

Russia New York, NY

324

2

1

Abelson, Mrs. Samuel (Hannah Wizosky)

female

28

1

0

P/PP 3381

24

?

C

10

?

Russia New York, NY

606

3

1

Abrahamsson, Mr. Abraham August Johannes

male

20

0

0

SOTON/O2 3101284

7.925

?

S

15

?

Taalintehdas, Finland Hoboken, NJ

607

3

1

Abrahim, Mrs. Joseph (Sophie Halaut Easu)

female

18

0

0

2657

7.2292

?

C

C

?

Greensburg, PA

608

3

0

Adahl, Mr. Mauritz Nils Martin

male

30

0

0

C 7076

7.25

?

S

?

72

Asarum, Sweden Brooklyn, NY

609

3

0

Adams, Mr. John

male

26

0

0

341826

8.05

?

S

?

103

Bournemouth, England

610

3

0

Ahlin, Mrs. Johan (Johanna Persdotter Larsson)

female

40

1

0

7546

9.475

?

S

?

?

Sweden Akeley, MN

611

3

1

Aks, Master. Philip Frank

male

0.8333

0

1

392091

9.35

?

S

11

?

London, England Norfolk, VA

612

3

1

Aks, Mrs. Sam (Leah Rosen)

female

18

0

1

392091

9.35

?

S

13

?

London, England Norfolk, VA

613

3

1

Albimona, Mr. Nassef Cassem

male

26

0

0

2699

18.7875

?

C

15

?

Syria Fredericksburg, VA

325

2

0

Aldworth, Mr. Charles Augustus

male

30

0

0

248744

13

?

S

?

?

Bryn Mawr, PA, USA

614

3

0

Alexander, Mr. William

male

26

0

0

3474

7.8875

?

S

?

?

England Albion, NY

615

3

0

Alhomaki, Mr. Ilmari Rudolf

male

20

0

0

SOTON/O2 3101287

7.925

?

S

?

?

Salo, Finland Astoria, OR

616

3

0

Ali, Mr. Ahmed

male

24

0

0

SOTON/O.Q. 3101311

7.05

?

S

?

?

?

In [45]:

countries

Out[45]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

0

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

1

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

3

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

4

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

144

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

145

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

146

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

147

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

148

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 20 columns

In [49]:

countries.set_index('Country name').sort_index(ascending = False)

Out[49]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

Zambia

Sub-Saharan Africa

4.073

0.069

4.209

3.938

8.145

0.708

55.809

0.782

0.061

0.823

2.43

0.528

0.552

0.231

0.487

0.227

0.074

1.975

Yemen

Middle East and North Africa

3.658

0.070

3.794

3.521

7.578

0.832

57.122

0.602

-0.147

0.800

2.43

0.329

0.831

0.272

0.268

0.092

0.089

1.776

Vietnam

Southeast Asia

5.411

0.039

5.488

5.334

8.973

0.850

68.034

0.940

-0.098

0.796

2.43

0.817

0.873

0.616

0.679

0.124

0.091

2.211

Venezuela

Latin America and Caribbean

4.892

0.064

5.017

4.767

9.073

0.861

66.700

0.615

-0.169

0.827

2.43

0.852

0.897

0.574

0.284

0.078

0.072

2.135

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Armenia

Commonwealth of Independent States

5.283

0.058

5.397

5.168

9.487

0.799

67.055

0.825

-0.168

0.629

2.43

0.996

0.758

0.585

0.540

0.079

0.198

2.127

Argentina

Latin America and Caribbean

5.929

0.056

6.040

5.819

9.962

0.898

69.000

0.828

-0.182

0.834

2.43

1.162

0.980

0.646

0.544

0.069

0.067

2.461

Algeria

Middle East and North Africa

4.887

0.053

4.991

4.783

9.342

0.802

66.005

0.480

-0.067

0.752

2.43

0.946

0.765

0.552

0.119

0.144

0.120

2.242

Albania

Central and Eastern Europe

5.117

0.059

5.234

5.001

9.520

0.697

68.999

0.785

-0.030

0.901

2.43

1.008

0.529

0.646

0.491

0.168

0.024

2.250

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 19 columns

In [67]:

titanic.pclass.value_counts().sort_values()

Out[67]:

2    277

1    323

3    709

Name: pclass, dtype: int64

In [69]:

titanic.pclass.value_counts().sort_index().plot(kind = 'bar')

Out[69]:

<Axes: >

 

In [70]:

titanic.pclass.value_counts().sort_values().plot(kind = 'bar')

Out[70]:

<Axes: >

 

In [76]:

houses.bedrooms.value_counts().sort_index().plot(kind = 'bar')

Out[76]:

<Axes: >

 

In [77]:

countries.head()

Out[77]:

 

Country name

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

0

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.0

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

1

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.7

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

2

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.4

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

3

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.0

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

4

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.4

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

In [78]:

countries['Ladder score']

Out[78]:

0      7.842

1      7.620

2      7.571

3      7.554

4      7.464

       ...  

144    3.512

145    3.467

146    3.415

147    3.145

148    2.523

Name: Ladder score, Length: 149, dtype: float64

In [88]:

df = countries.set_index('Country name')df

Out[88]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finland

Western Europe

7.842

0.032

7.904

7.780

10.775

0.954

72.000

0.949

-0.098

0.186

2.43

1.446

1.106

0.741

0.691

0.124

0.481

3.253

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

Switzerland

Western Europe

7.571

0.036

7.643

7.500

11.117

0.942

74.400

0.919

0.025

0.292

2.43

1.566

1.079

0.816

0.653

0.204

0.413

2.839

Iceland

Western Europe

7.554

0.059

7.670

7.438

10.878

0.983

73.000

0.955

0.160

0.673

2.43

1.482

1.172

0.772

0.698

0.293

0.170

2.967

Netherlands

Western Europe

7.464

0.027

7.518

7.410

10.932

0.942

72.400

0.913

0.175

0.338

2.43

1.501

1.079

0.753

0.647

0.302

0.384

2.798

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Lesotho

Sub-Saharan Africa

3.512

0.120

3.748

3.276

7.926

0.787

48.700

0.715

-0.131

0.915

2.43

0.451

0.731

0.007

0.405

0.103

0.015

1.800

Botswana

Sub-Saharan Africa

3.467

0.074

3.611

3.322

9.782

0.784

59.269

0.824

-0.246

0.801

2.43

1.099

0.724

0.340

0.539

0.027

0.088

0.648

Rwanda

Sub-Saharan Africa

3.415

0.068

3.548

3.282

7.676

0.552

61.400

0.897

0.061

0.167

2.43

0.364

0.202

0.407

0.627

0.227

0.493

1.095

Zimbabwe

Sub-Saharan Africa

3.145

0.058

3.259

3.030

7.943

0.750

56.201

0.677

-0.047

0.821

2.43

0.457

0.649

0.243

0.359

0.157

0.075

1.205

Afghanistan

South Asia

2.523

0.038

2.596

2.449

7.695

0.463

52.493

0.382

-0.102

0.924

2.43

0.370

0.000

0.126

0.000

0.122

0.010

1.895

149 rows × 19 columns

In [96]:

df.loc[['India','Canada','United Kingdom','United States']]

Out[96]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

India

South Asia

3.819

0.026

3.869

3.769

8.755

0.603

60.633

0.893

0.089

0.774

2.43

0.741

0.316

0.383

0.622

0.246

0.106

1.405

Canada

North America and ANZ

7.103

0.042

7.185

7.021

10.776

0.926

73.800

0.915

0.089

0.415

2.43

1.447

1.044

0.798

0.648

0.246

0.335

2.585

United Kingdom

Western Europe

7.064

0.038

7.138

6.990

10.707

0.934

72.500

0.859

0.233

0.459

2.43

1.423

1.062

0.757

0.580

0.340

0.306

2.596

United States

North America and ANZ

6.951

0.049

7.047

6.856

11.023

0.920

68.200

0.837

0.098

0.698

2.43

1.533

1.030

0.621

0.554

0.252

0.154

2.807

In [97]:

titanic.loc[[8,9,896]]

Out[97]:

 

pclass

survived

name

sex

age

sibsp

parch

ticket

fare

cabin

embarked

boat

body

home.dest

8

1

1

Appleton, Mrs. Edward Dale (Charlotte Lamson)

female

53

2

0

11769

51.4792

C101

S

D

?

Bayside, Queens, NY

9

1

0

Artagaveytia, Mr. Ramon

male

71

0

0

PC 17609

49.5042

?

C

?

22

Montevideo, Uruguay

896

3

0

Johnson, Mr. Alfred

male

49

0

0

LINE

0

?

S

?

?

?

In [99]:

titanic.loc[5:10]

Out[99]:

 

pclass

survived

name

sex

age

sibsp

parch

ticket

fare

cabin

embarked

boat

body

home.dest

5

1

1

Anderson, Mr. Harry

male

48

0

0

19952

26.55

E12

S

3

?

New York, NY

6

1

1

Andrews, Miss. Kornelia Theodosia

female

63

1

0

13502

77.9583

D7

S

10

?

Hudson, NY

7

1

0

Andrews, Mr. Thomas Jr

male

39

0

0

112050

0

A36

S

?

?

Belfast, NI

8

1

1

Appleton, Mrs. Edward Dale (Charlotte Lamson)

female

53

2

0

11769

51.4792

C101

S

D

?

Bayside, Queens, NY

9

1

0

Artagaveytia, Mr. Ramon

male

71

0

0

PC 17609

49.5042

?

C

?

22

Montevideo, Uruguay

10

1

0

Astor, Col. John Jacob

male

47

1

0

PC 17757

227.525

C62 C64

C

?

124

New York, NY

In [100]:

titanic.loc[1:100:2]

Out[100]:

 

pclass

survived

name

sex

age

sibsp

parch

ticket

fare

cabin

embarked

boat

body

home.dest

1

1

1

Allison, Master. Hudson Trevor

male

0.9167

1

2

113781

151.55

C22 C26

S

11

?

Montreal, PQ / Chesterville, ON

3

1

0

Allison, Mr. Hudson Joshua Creighton

male

30

1

2

113781

151.55

C22 C26

S

?

135

Montreal, PQ / Chesterville, ON

5

1

1

Anderson, Mr. Harry

male

48

0

0

19952

26.55

E12

S

3

?

New York, NY

7

1

0

Andrews, Mr. Thomas Jr

male

39

0

0

112050

0

A36

S

?

?

Belfast, NI

9

1

0

Artagaveytia, Mr. Ramon

male

71

0

0

PC 17609

49.5042

?

C

?

22

Montevideo, Uruguay

11

1

1

Astor, Mrs. John Jacob (Madeleine Talmadge Force)

female

18

1

0

PC 17757

227.525

C62 C64

C

4

?

New York, NY

13

1

1

Barber, Miss. Ellen 'Nellie'

female

26

0

0

19877

78.85

?

S

6

?

?

15

1

0

Baumann, Mr. John D

male

?

0

0

PC 17318

25.925

?

S

?

?

New York, NY

17

1

1

Baxter, Mrs. James (Helene DeLaudeniere Chaput)

female

50

0

1

PC 17558

247.5208

B58 B60

C

6

?

Montreal, PQ

19

1

0

Beattie, Mr. Thomson

male

36

0

0

13050

75.2417

C6

C

A

?

Winnipeg, MN

21

1

1

Beckwith, Mrs. Richard Leonard (Sallie Monypeny)

female

47

1

1

11751

52.5542

D35

S

5

?

New York, NY

23

1

1

Bidois, Miss. Rosalie

female

42

0

0

PC 17757

227.525

?

C

4

?

?

25

1

0

Birnbaum, Mr. Jakob

male

25

0

0

13905

26

?

C

?

148

San Francisco, CA

27

1

1

Bishop, Mrs. Dickinson H (Helen Walton)

female

19

1

0

11967

91.0792

B49

C

7

?

Dowagiac, MI

29

1

1

Bjornstrom-Steffansson, Mr. Mauritz Hakan

male

28

0

0

110564

26.55

C52

S

D

?

Stockholm, Sweden / Washington, DC

31

1

1

Blank, Mr. Henry

male

40

0

0

112277

31

A31

C

7

?

Glen Ridge, NJ

33

1

1

Bonnell, Miss. Elizabeth

female

58

0

0

113783

26.55

C103

S

8

?

Birkdale, England Cleveland, Ohio

35

1

1

Bowen, Miss. Grace Scott

female

45

0

0

PC 17608

262.375

?

C

4

?

Cooperstown, NY

37

1

1

Bradley, Mr. George ('George Arthur Brayton')

male

?

0

0

111427

26.55

?

S

9

?

Los Angeles, CA

39

1

0

Brandeis, Mr. Emil

male

48

0

0

PC 17591

50.4958

B10

C

?

208

Omaha, NE

41

1

1

Brown, Mrs. James Joseph (Margaret Tobin)

female

44

0

0

PC 17610

27.7208

B4

C

6

?

Denver, CO

43

1

1

Bucknell, Mrs. William Robert (Emma Eliza Ward)

female

60

0

0

11813

76.2917

D15

C

8

?

Philadelphia, PA

45

1

0

Butt, Major. Archibald Willingham

male

45

0

0

113050

26.55

B38

S

?

?

Washington, DC

47

1

1

Calderhead, Mr. Edward Pennington

male

42

0

0

PC 17476

26.2875

E24

S

5

?

New York, NY

49

1

1

Cardeza, Mr. Thomas Drake Martinez

male

36

0

1

PC 17755

512.3292

B51 B53 B55

C

3

?

Austria-Hungary / Germantown, Philadelphia, PA

51

1

0

Carlsson, Mr. Frans Olof

male

33

0

0

695

5

B51 B53 B55

S

?

?

New York, NY

53

1

0

Carrau, Mr. Jose Pedro

male

17

0

0

113059

47.1

?

S

?

?

Montevideo, Uruguay

55

1

1

Carter, Miss. Lucile Polk

female

14

1

2

113760

120

B96 B98

S

4

?

Bryn Mawr, PA

57

1

1

Carter, Mrs. William Ernest (Lucile Polk)

female

36

1

2

113760

120

B96 B98

S

4

?

Bryn Mawr, PA

59

1

1

Cassebeer, Mrs. Henry Arthur Jr (Eleanor Genev...

female

?

0

0

17770

27.7208

?

C

5

?

New York, NY

61

1

1

Cavendish, Mrs. Tyrell William (Julia Florence...

female

76

1

0

19877

78.85

C46

S

6

?

Little Onn Hall, Staffs

63

1

1

Chaffee, Mrs. Herbert Fuller (Carrie Constance...

female

47

1

0

W.E.P. 5734

61.175

E31

S

4

?

Amenia, ND

65

1

1

Chambers, Mrs. Norman Campbell (Bertha Griggs)

female

33

1

0

113806

53.1

E8

S

5

?

New York, NY / Ithaca, NY

67

1

1

Cherry, Miss. Gladys

female

30

0

0

110152

86.5

B77

S

8

?

London, England

69

1

1

Chibnall, Mrs. (Edith Martha Bowerman)

female

?

0

1

113505

55

E33

S

6

?

St Leonards-on-Sea, England Ohio

71

1

0

Clark, Mr. Walter Miller

male

27

1

0

13508

136.7792

C89

C

?

?

Los Angeles, CA

73

1

1

Cleaver, Miss. Alice

female

22

0

0

113781

151.55

?

S

11

?

?

75

1

0

Colley, Mr. Edward Pomeroy

male

47

0

0

5727

25.5875

E58

S

?

?

Victoria, BC

77

1

0

Compton, Mr. Alexander Taylor Jr

male

37

1

1

PC 17756

83.1583

E52

C

?

?

Lakewood, NJ

79

1

1

Cornell, Mrs. Robert Clifford (Malvina Helen L...

female

55

2

0

11770

25.7

C101

S

2

?

New York, NY

81

1

0

Crosby, Capt. Edward Gifford

male

70

1

1

WE/P 5735

71

B22

S

?

269

Milwaukee, WI

83

1

1

Crosby, Mrs. Edward Gifford (Catherine Elizabe...

female

64

1

1

112901

26.55

B26

S

7

?

Milwaukee, WI

85

1

1

Cumings, Mrs. John Bradley (Florence Briggs Th...

female

38

1

0

PC 17599

71.2833

C85

C

4

?

New York, NY

87

1

1

Daniel, Mr. Robert Williams

male

27

0

0

113804

30.5

?

S

3

?

Philadelphia, PA

89

1

0

Davidson, Mr. Thornton

male

31

1

0

F.C. 12750

52

B71

S

?

?

Montreal, PQ

91

1

1

Dick, Mr. Albert Adrian

male

31

1

0

17474

57

B20

S

3

?

Calgary, AB

93

1

1

Dodge, Dr. Washington

male

53

1

1

33638

81.8583

A34

S

13

?

San Francisco, CA

95

1

1

Dodge, Mrs. Washington (Ruth Vidaver)

female

54

1

1

33638

81.8583

A34

S

5

?

San Francisco, CA

97

1

1

Douglas, Mrs. Frederick Charles (Mary Helene B...

female

27

1

1

PC 17558

247.5208

B58 B60

C

6

?

Montreal, PQ

99

1

1

Duff Gordon, Lady. (Lucille Christiana Sutherl...

female

48

1

0

11755

39.6

A16

C

1

?

London / Paris

In [107]:

df.sort_index().loc['Denmark':'France':2]

Out[107]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Denmark

Western Europe

7.620

0.035

7.687

7.552

10.933

0.954

72.700

0.946

0.030

0.179

2.43

1.502

1.108

0.763

0.686

0.208

0.485

2.868

Ecuador

Latin America and Caribbean

5.764

0.057

5.875

5.653

9.313

0.821

68.800

0.842

-0.124

0.843

2.43

0.935

0.806

0.640

0.560

0.107

0.062

2.653

El Salvador

Latin America and Caribbean

6.061

0.065

6.188

5.933

9.054

0.762

66.402

0.888

-0.110

0.688

2.43

0.845

0.675

0.565

0.615

0.116

0.160

3.085

Ethiopia

Sub-Saharan Africa

4.275

0.051

4.374

4.175

7.694

0.764

59.000

0.752

0.082

0.761

2.43

0.370

0.679

0.331

0.451

0.241

0.114

2.089

France

Western Europe

6.690

0.037

6.762

6.618

10.704

0.942

74.000

0.822

-0.147

0.571

2.43

1.421

1.081

0.804

0.536

0.092

0.235

2.521

In [112]:

df.iloc[20:100:2]

Out[112]:

 

Regional indicator

Ladder score

Standard error of ladder score

upperwhisker

lowerwhisker

Logged GDP per capita

Social support

Healthy life expectancy

Freedom to make life choices

Generosity

Perceptions of corruption

Ladder score in Dystopia

Explained by: Log GDP per capita

Explained by: Social support

Explained by: Healthy life expectancy

Explained by: Freedom to make life choices

Explained by: Generosity

Explained by: Perceptions of corruption

Dystopia + residual

Country name

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

France

Western Europe

6.690

0.037

6.762

6.618

10.704

0.942

74.000

0.822

-0.147

0.571

2.43

1.421

1.081

0.804

0.536

0.092

0.235

2.521

Malta

Western Europe

6.602

0.044

6.688

6.516

10.674

0.931

72.200

0.927

0.133

0.653

2.43

1.411

1.055

0.747

0.664

0.275

0.183

2.268

United Arab Emirates

Middle East and North Africa

6.561

0.039

6.637

6.484

11.085

0.844

67.333

0.932

0.074

0.589

2.43

1.555

0.860

0.594

0.670

0.236

0.223

2.422

Spain

Western Europe

6.491

0.042

6.574

6.408

10.571

0.932

74.700

0.761

-0.081

0.745

2.43

1.375

1.057

0.826

0.462

0.135

0.124

2.513

Slovenia

Central and Eastern Europe

6.461

0.043

6.546

6.376

10.529

0.948

71.400

0.949

-0.101

0.806

2.43

1.360

1.093

0.722

0.690

0.122

0.085

2.388

Uruguay

Latin America and Caribbean

6.431

0.046

6.521

6.341

9.966

0.925

69.100

0.896

-0.092

0.590

2.43

1.164

1.042

0.649

0.625

0.128

0.223

2.600

Kosovo

Central and Eastern Europe

6.372

0.059

6.487

6.257

9.318

0.821

63.813

0.869

0.257

0.917

2.43

0.937

0.807

0.483

0.593

0.356

0.014

3.182

Brazil

Latin America and Caribbean

6.330

0.043

6.415

6.245

9.577

0.882

66.601

0.804

-0.071

0.756

2.43

1.028

0.944

0.571

0.514

0.142

0.117

3.015

Jamaica

Latin America and Caribbean

6.309

0.156

6.615

6.004

9.186

0.877

67.500

0.890

-0.137

0.884

2.43

0.891

0.932

0.599

0.618

0.099

0.035

3.135

Cyprus

Western Europe

6.223

0.049

6.319

6.128

10.576

0.802

73.898

0.763

-0.015

0.844

2.43

1.377

0.765

0.801

0.464

0.178

0.061

2.578

Panama

Latin America and Caribbean

6.180

0.073

6.323

6.036

10.350

0.896

69.652

0.872

-0.166

0.856

2.43

1.298

0.976

0.667

0.596

0.079

0.053

2.509

Chile

Latin America and Caribbean

6.172

0.046

6.262

6.081

10.071

0.882

70.000

0.742

-0.044

0.830

2.43

1.200

0.946

0.678

0.438

0.159

0.070

2.682

Kazakhstan

Commonwealth of Independent States

6.152

0.047

6.243

6.060

10.155

0.952

65.200

0.853

-0.069

0.733

2.43

1.230

1.103

0.527

0.573

0.143

0.132

2.446

Kuwait

Middle East and North Africa

6.106

0.066

6.235

5.977

10.817

0.843

66.900

0.867

-0.104

0.736

2.43

1.461

0.857

0.580

0.591

0.120

0.130

2.368

El Salvador

Latin America and Caribbean

6.061

0.065

6.188

5.933

9.054

0.762

66.402

0.888

-0.110

0.688

2.43

0.845

0.675

0.565

0.615

0.116

0.160

3.085

Latvia

Central and Eastern Europe

6.032

0.036

6.103

5.961

10.315

0.927

67.100

0.715

-0.162

0.800

2.43

1.285

1.047

0.587

0.405

0.082

0.089

2.536

Hungary

Central and Eastern Europe

5.992

0.047

6.085

5.899

10.358

0.943

68.000

0.755

-0.186

0.876

2.43

1.301

1.083

0.615

0.454

0.067

0.040

2.432

Nicaragua

Latin America and Caribbean

5.972

0.083

6.134

5.810

8.620

0.864

67.657

0.836

0.020

0.664

2.43

0.693

0.904

0.604

0.553

0.201

0.176

2.841

Argentina

Latin America and Caribbean

5.929

0.056

6.040

5.819

9.962

0.898

69.000

0.828

-0.182

0.834

2.43

1.162

0.980

0.646

0.544

0.069

0.067

2.461

Honduras

Latin America and Caribbean

5.919

0.082

6.081

5.758

8.648

0.812

67.300

0.857

0.081

0.809

2.43

0.703

0.787

0.593

0.578

0.241

0.083

2.934

Philippines

Southeast Asia

5.880

0.052

5.982

5.778

9.076

0.830

62.000

0.917

-0.097

0.742

2.43

0.853

0.828

0.426

0.651

0.125

0.126

2.872

Peru

Latin America and Caribbean

5.840

0.075

5.988

5.692

9.458

0.832

68.250

0.822

-0.154

0.891

2.43

0.986

0.833

0.623

0.536

0.087

0.031

2.744

Moldova

Commonwealth of Independent States

5.766

0.046

5.856

5.677

9.454

0.857

65.699

0.822

-0.079

0.918

2.43

0.985

0.888

0.542

0.536

0.137

0.013

2.665

Kyrgyzstan

Commonwealth of Independent States

5.744

0.046

5.834

5.653

8.538

0.893

64.401

0.935

0.119

0.908

2.43

0.665

0.971

0.501

0.673

0.266

0.020

2.648

Bolivia

Latin America and Caribbean

5.716

0.053

5.819

5.613

9.046

0.810

63.901

0.875

-0.077

0.839

2.43

0.842

0.782

0.486

0.600

0.138

0.064

2.805

Paraguay

Latin America and Caribbean

5.653

0.092

5.832

5.473

9.448

0.893

65.900

0.876

0.028

0.882

2.43

0.983

0.970

0.549

0.602

0.206

0.037

2.306

Dominican Republic

Latin America and Caribbean

5.545

0.071

5.685

5.405

9.802

0.853

66.102

0.860

-0.133

0.714

2.43

1.106

0.879

0.555

0.581

0.101

0.144

2.178

Belarus

Commonwealth of Independent States

5.534

0.047

5.625

5.442

9.853

0.910

66.253

0.650

-0.180

0.627

2.43

1.124

1.007

0.560

0.326

0.070

0.199

2.247

Hong Kong S.A.R. of China

East Asia

5.477

0.049

5.573

5.380

11.000

0.836

76.820

0.717

0.067

0.403

2.43

1.525

0.841

0.893

0.408

0.232

0.342

1.236

Vietnam

Southeast Asia

5.411

0.039

5.488

5.334

8.973

0.850

68.034

0.940

-0.098

0.796

2.43

0.817

0.873

0.616

0.679

0.124

0.091

2.211

Malaysia

Southeast Asia

5.384

0.049

5.480

5.289

10.238

0.817

67.102

0.895

0.125

0.839

2.43

1.259

0.797

0.587

0.624

0.270

0.064

1.784

Congo (Brazzaville)

Sub-Saharan Africa

5.342

0.097

5.533

5.151

8.117

0.636

58.221

0.695

-0.068

0.745

2.43

0.518

0.392

0.307

0.381

0.144

0.124

3.476

Ivory Coast

Sub-Saharan Africa

5.306

0.078

5.460

5.152

8.551

0.644

50.114

0.741

-0.016

0.794

2.43

0.669

0.409

0.052

0.438

0.177

0.092

3.469

Nepal

South Asia

5.269

0.070

5.406

5.132

8.120

0.774

64.233

0.782

0.152

0.727

2.43

0.519

0.702

0.496

0.488

0.287

0.135

2.642

Maldives

South Asia

5.198

0.072

5.339

5.057

9.826

0.913

70.600

0.854

0.024

0.825

2.43

1.115

1.015

0.697

0.575

0.204

0.073

1.520

Cameroon

Sub-Saharan Africa

5.142

0.074

5.288

4.996

8.189

0.710

53.515

0.731

0.026

0.848

2.43

0.543

0.556

0.159

0.425

0.205

0.058

3.195

Albania

Central and Eastern Europe

5.117

0.059

5.234

5.001

9.520

0.697

68.999

0.785

-0.030

0.901

2.43

1.008

0.529

0.646

0.491

0.168

0.024

2.250

Ghana

Sub-Saharan Africa

5.088

0.067

5.219

4.958

8.580

0.727

57.586

0.807

0.123

0.848

2.43

0.680

0.595

0.287

0.517

0.268

0.058

2.684

Turkmenistan

Commonwealth of Independent States

5.066

0.036

5.136

4.996

9.629

0.983

62.409

0.877

0.273

0.888

2.43

1.046

1.172

0.439

0.602

0.366

0.033

1.409

Benin

Sub-Saharan Africa

5.045

0.073

5.189

4.901

8.087

0.489

54.713

0.757

-0.034

0.661

2.43

0.507

0.058

0.196

0.457

0.166

0.178

3.482

In [120]:

house = houses.sort_index(ascending = False)house

Out[120]:

 

id

date

price

bedrooms

bathrooms

sqft_living

sqft_lot

floors

waterfront

view

...

grade

sqft_above

sqft_basement

yr_built

yr_renovated

zipcode

lat

long

sqft_living15

sqft_lot15

21612

1523300157

20141015T000000

325000.0

2

0.75

1020

1076

2.0

0

0

...

7

1020

0

2008

0

98144

47.5941

-122.299

1020

1357

21611

291310100

20150116T000000

400000.0

3

2.50

1600

2388

2.0

0

0

...

8

1600

0

2004

0

98027

47.5345

-122.069

1410

1287

21610

1523300141

20140623T000000

402101.0

2

0.75

1020

1350

2.0

0

0

...

7

1020

0

2009

0

98144

47.5944

-122.299

1020

2007

21609

6600060120

20150223T000000

400000.0

4

2.50

2310

5813

2.0

0

0

...

8

2310

0

2014

0

98146

47.5107

-122.362

1830

7200

21608

263000018

20140521T000000

360000.0

3

2.50

1530

1131

3.0

0

0

...

8

1530

0

2009

0

98103

47.6993

-122.346

1530

1509

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

4

1954400510

20150218T000000

510000.0

3

2.00

1680

8080

1.0

0

0

...

8

1680

0

1987

0

98074

47.6168

-122.045

1800

7503

3

2487200875

20141209T000000

604000.0

4

3.00

1960

5000

1.0

0

0

...

7

1050

910

1965

0

98136

47.5208

-122.393

1360

5000

2

5631500400

20150225T000000

180000.0

2

1.00

770

10000

1.0

0

0

...

6

770

0

1933

0

98028

47.7379

-122.233

2720

8062

1

6414100192

20141209T000000

538000.0

3

2.25

2570

7242

2.0

0

0

...

7

2170

400

1951

1991

98125

47.7210

-122.319

1690

7639

0

7129300520

20141013T000000

221900.0

3

1.00

1180

5650

1.0

0

0

...

7

1180

0

1955

0

98178

47.5112

-122.257

1340

5650

21613 rows × 21 columns

In [126]:

house.loc[21612:21611, ['price', 'bedrooms']]

Out[126]:

 

price

bedrooms

21612

325000.0

2

21611

400000.0

3

In [129]:

titanic.loc[50:60:2, ['name', 'sex', 'age']]

Out[129]:

 

name

sex

age

50

Cardeza, Mrs. James Warburton Martinez (Charlo...

female

58

52

Carrau, Mr. Francisco M

male

28

54

Carter, Master. William Thornton II

male

11

56

Carter, Mr. William Ernest

male

36

58

Case, Mr. Howard Brown

male

49

60

Cavendish, Mr. Tyrell William

male

36

In [132]:

df.loc['Denmark':'Canada', 'Ladder score']

Out[132]:

Country name

Denmark        7.620

Switzerland    7.571

Iceland        7.554

Netherlands    7.464

Norway         7.392

Sweden         7.363

Luxembourg     7.324

New Zealand    7.277

Austria        7.268

Australia      7.183

Israel         7.157

Germany        7.155

Canada         7.103

Name: Ladder score, dtype: float64

In [139]:

houses = pd.read_csv('kc_house_data.csv')houses

Out[139]:

 

id

date

price

bedrooms

bathrooms

sqft_living

sqft_lot

floors

waterfront

view

...

grade

sqft_above

sqft_basement

yr_built

yr_renovated

zipcode

lat

long

sqft_living15

sqft_lot15

0

7129300520

20141013T000000

221900.0

3

1.00

1180

5650

1.0

0

0

...

7

1180

0

1955

0

98178

47.5112

-122.257

1340

5650

1

6414100192

20141209T000000

538000.0

3

2.25

2570

7242

2.0

0

0

...

7

2170

400

1951

1991

98125

47.7210

-122.319

1690

7639

2

5631500400

20150225T000000

180000.0

2

1.00

770

10000

1.0

0

0

...

6

770

0

1933

0

98028

47.7379

-122.233

2720

8062

3

2487200875

20141209T000000

604000.0

4

3.00

1960

5000

1.0

0

0

...

7

1050

910

1965

0

98136

47.5208

-122.393

1360

5000

4

1954400510

20150218T000000

510000.0

3

2.00

1680

8080

1.0

0

0

...

8

1680

0

1987

0

98074

47.6168

-122.045

1800

7503

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

21608

263000018

20140521T000000

360000.0

3

2.50

1530

1131

3.0

0

0

...

8

1530

0

2009

0

98103

47.6993

-122.346

1530

1509

21609

6600060120

20150223T000000

400000.0

4

2.50

2310

5813

2.0

0

0

...

8

2310

0

2014

0

98146

47.5107

-122.362

1830

7200

21610

1523300141

20140623T000000

402101.0

2

0.75

1020

1350

2.0

0

0

...

7

1020

0

2009

0

98144

47.5944

-122.299

1020

2007

21611

291310100

20150116T000000

400000.0

3

2.50

1600

2388

2.0

0

0

...

8

1600

0

2004

0

98027

47.5345

-122.069

1410

1287

21612

1523300157

20141015T000000

325000.0

2

0.75

1020

1076

2.0

0

0

...

7

1020

0

2008

0

98144

47.5941

-122.299

1020

1357

21613 rows × 21 columns

In [143]:

houses['bedrooms'].value_counts().loc[33]

Out[143]:

1

In [145]:

titanic.info()

<class 'pandas.core.frame.DataFrame'>

RangeIndex: 1309 entries, 0 to 1308

Data columns (total 14 columns):

 #   Column     Non-Null Count  Dtype

---  ------     --------------  -----

 0   pclass     1309 non-null   int64

 1   survived   1309 non-null   int64

 2   name       1309 non-null   object

 3   sex        1309 non-null   object

 4   age        1309 non-null   object

 5   sibsp      1309 non-null   int64

 6   parch      1309 non-null   int64

 7   ticket     1309 non-null   object

 8   fare       1309 non-null   object

 9   cabin      1309 non-null   object

 10  embarked   1309 non-null   object

 11  boat       1309 non-null   object

 12  body       1309 non-null   object

 13  home.dest  1309 non-null   object

dtypes: int64(4), object(10)

memory usage: 143.3+ KB

In [151]:

titanic['age'].value_counts().iloc[0:5]

Out[151]:

?     263

24     47

22     43

21     41

30     40

Name: age, dtype: int64

In [152]:

pokemon = pd.read_csv('pokemon.csv')pokemon

Out[152]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

0

1

Bulbasaur

Grass

Poison

318

45

49

49

65

65

45

1

False

1

2

Ivysaur

Grass

Poison

405

60

62

63

80

80

60

2

False

2

3

Venusaur

Grass

Poison

525

80

82

83

100

100

80

3

False

3

4

Charmander

Fire

NaN

309

39

52

43

60

50

65

1

False

4

5

Charmeleon

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

146

147

Dratini

Dragon

NaN

300

41

64

45

50

50

50

1

False

147

148

Dragonair

Dragon

NaN

420

61

84

65

70

70

70

2

False

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

150

151

Mew

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 13 columns

In [153]:

pokemon.set_index('Name')

Out[153]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Bulbasaur

1

Grass

Poison

318

45

49

49

65

65

45

1

False

Ivysaur

2

Grass

Poison

405

60

62

63

80

80

60

2

False

Venusaur

3

Grass

Poison

525

80

82

83

100

100

80

3

False

Charmander

4

Fire

NaN

309

39

52

43

60

50

65

1

False

Charmeleon

5

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

Dratini

147

Dragon

NaN

300

41

64

45

50

50

50

1

False

Dragonair

148

Dragon

NaN

420

61

84

65

70

70

70

2

False

Dragonite

149

Dragon

Flying

600

91

134

95

100

100

80

3

False

Mewtwo

150

Psychic

NaN

680

106

110

90

154

90

130

1

True

Mew

151

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 12 columns

In [158]:

pokemon.sort_values('Attack', ascending = False)

Out[158]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

111

112

Rhydon

Ground

Rock

485

105

130

120

45

45

40

2

False

135

136

Flareon

Fire

NaN

525

65

130

60

95

110

65

2

False

67

68

Machamp

Fighting

NaN

505

90

130

80

65

85

55

3

False

98

99

Kingler

Water

NaN

475

55

130

115

50

50

75

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

13

14

Kakuna

Bug

Poison

205

45

25

50

25

25

35

2

False

62

63

Abra

Psychic

NaN

310

25

20

15

105

55

90

1

False

10

11

Metapod

Bug

NaN

205

50

20

55

25

25

30

2

False

128

129

Magikarp

Water

NaN

200

20

10

55

15

20

80

1

False

112

113

Chansey

Normal

NaN

450

250

5

5

35

105

50

1

False

151 rows × 13 columns

In [164]:

pokemon.sort_values(['Total','Attack','Sp. Atk'], ascending = False)

Out[164]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

150

151

Mew

Psychic

NaN

600

100

100

100

100

100

100

1

False

145

146

Moltres

Fire

Flying

580

90

100

90

125

85

90

1

True

144

145

Zapdos

Electric

Flying

580

90

90

85

125

90

100

1

True

...

...

...

...

...

...

...

...

...

...

...

...

...

...

13

14

Kakuna

Bug

Poison

205

45

25

50

25

25

35

2

False

10

11

Metapod

Bug

NaN

205

50

20

55

25

25

30

2

False

128

129

Magikarp

Water

NaN

200

20

10

55

15

20

80

1

False

12

13

Weedle

Bug

Poison

195

40

35

30

20

20

50

1

False

9

10

Caterpie

Bug

NaN

195

45

30

35

20

20

45

1

False

151 rows × 13 columns

In [169]:

pokemon.set_index('Name').sort_index().tail(20)

Out[169]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Staryu

120

Water

NaN

340

30

45

55

70

55

85

1

False

Tangela

114

Grass

NaN

435

65

55

115

100

40

60

1

False

Tauros

128

Normal

NaN

490

75

100

95

40

70

110

1

False

Tentacool

72

Water

Poison

335

40

40

35

50

100

70

1

False

Tentacruel

73

Water

Poison

515

80

70

65

80

120

100

2

False

Vaporeon

134

Water

NaN

525

130

65

60

110

95

65

2

False

Venomoth

49

Bug

Poison

450

70

65

60

90

75

90

2

False

Venonat

48

Bug

Poison

305

60

55

50

40

55

45

1

False

Venusaur

3

Grass

Poison

525

80

82

83

100

100

80

3

False

Victreebel

71

Grass

Poison

490

80

105

65

100

70

70

3

False

Vileplume

45

Grass

Poison

490

75

80

85

110

90

50

3

False

Voltorb

100

Electric

NaN

330

40

30

50

55

55

100

1

False

Vulpix

37

Fire

NaN

299

38

41

40

50

65

65

1

False

Wartortle

8

Water

NaN

405

59

63

80

65

80

58

2

False

Weedle

13

Bug

Poison

195

40

35

30

20

20

50

1

False

Weepinbell

70

Grass

Poison

390

65

90

50

85

45

55

2

False

Weezing

110

Poison

NaN

490

65

90

120

85

70

60

2

False

Wigglytuff

40

Normal

Fairy

435

140

70

45

85

50

45

2

False

Zapdos

145

Electric

Flying

580

90

90

85

125

90

100

1

True

Zubat

41

Poison

Flying

245

40

45

35

30

40

55

1

False

In [172]:

pok_df = pokemon.sort_values('Speed',ascending = False)pok_df

Out[172]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

100

101

Electrode

Electric

NaN

480

60

50

70

80

80

140

2

False

141

142

Aerodactyl

Rock

Flying

515

80

105

65

60

75

130

1

False

134

135

Jolteon

Electric

NaN

525

65

65

60

110

95

130

2

False

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

64

65

Alakazam

Psychic

NaN

500

55

50

45

135

95

120

3

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

45

46

Paras

Bug

Grass

285

35

70

55

45

55

25

1

False

110

111

Rhyhorn

Ground

Rock

345

80

85

95

30

30

25

1

False

38

39

Jigglypuff

Normal

Fairy

270

115

45

20

45

25

20

1

False

73

74

Geodude

Rock

Ground

300

40

80

100

30

30

20

1

False

78

79

Slowpoke

Water

Psychic

315

90

65

65

40

40

15

1

False

151 rows × 13 columns

In [181]:

pok_df.head(10).describe()

Out[181]:

 

Num

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

count

10.000000

10.000000

10.000000

10.00000

10.000000

10.000000

10.000000

10.000000

10.000000

mean

97.200000

504.000000

66.100000

79.50000

67.500000

88.400000

80.500000

122.000000

1.800000

std

44.656218

72.141836

18.465884

21.53163

17.199806

36.999099

10.658851

10.055402

0.632456

min

26.000000

405.000000

35.000000

50.00000

45.000000

40.000000

65.000000

110.000000

1.000000

25%

56.000000

481.250000

60.000000

66.25000

56.250000

61.250000

71.250000

115.000000

1.250000

50%

111.000000

495.000000

62.500000

77.50000

62.500000

85.000000

80.000000

120.000000

2.000000

75%

133.250000

518.750000

72.500000

97.50000

81.250000

107.500000

88.750000

130.000000

2.000000

max

150.000000

680.000000

106.000000

110.00000

95.000000

154.000000

95.000000

140.000000

3.000000

In [182]:

pok_df.head(20).describe()

Out[182]:

 

Num

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

count

20.000000

20.00000

20.000000

20.000000

20.000000

20.000000

20.000000

20.000000

20.00000

mean

87.900000

498.55000

68.100000

80.200000

67.600000

87.800000

82.300000

112.550000

1.85000

std

44.750654

61.17832

16.861354

20.962623

17.135374

30.453761

14.382372

12.141599

0.67082

min

18.000000

400.00000

35.000000

35.000000

30.000000

40.000000

61.000000

100.000000

1.00000

25%

52.500000

479.75000

60.000000

68.750000

59.250000

64.000000

70.000000

104.000000

1.00000

50%

86.000000

500.00000

65.000000

80.000000

65.000000

80.500000

80.000000

110.000000

2.00000

75%

125.750000

515.00000

76.250000

100.000000

76.250000

102.500000

91.250000

120.000000

2.00000

max

151.000000

680.00000

106.000000

110.000000

100.000000

154.000000

120.000000

140.000000

3.00000

In [183]:

pok_df.value_counts('Type 1')

Out[183]:

Type 1

Water       28

Normal      22

Poison      14

Bug         12

Fire        12

Grass       12

Electric     9

Rock         9

Ground       8

Psychic      8

Fighting     7

Dragon       3

Ghost        3

Fairy        2

Ice          2

dtype: int64

In [187]:

pokemon = pd.read_csv('pokemon.csv')pokemon

Out[187]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

0

1

Bulbasaur

Grass

Poison

318

45

49

49

65

65

45

1

False

1

2

Ivysaur

Grass

Poison

405

60

62

63

80

80

60

2

False

2

3

Venusaur

Grass

Poison

525

80

82

83

100

100

80

3

False

3

4

Charmander

Fire

NaN

309

39

52

43

60

50

65

1

False

4

5

Charmeleon

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

146

147

Dratini

Dragon

NaN

300

41

64

45

50

50

50

1

False

147

148

Dragonair

Dragon

NaN

420

61

84

65

70

70

70

2

False

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

150

151

Mew

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 13 columns

In [189]:

pd = pokemon.set_index('Name')pd

Out[189]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Bulbasaur

1

Grass

Poison

318

45

49

49

65

65

45

1

False

Ivysaur

2

Grass

Poison

405

60

62

63

80

80

60

2

False

Venusaur

3

Grass

Poison

525

80

82

83

100

100

80

3

False

Charmander

4

Fire

NaN

309

39

52

43

60

50

65

1

False

Charmeleon

5

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

Dratini

147

Dragon

NaN

300

41

64

45

50

50

50

1

False

Dragonair

148

Dragon

NaN

420

61

84

65

70

70

70

2

False

Dragonite

149

Dragon

Flying

600

91

134

95

100

100

80

3

False

Mewtwo

150

Psychic

NaN

680

106

110

90

154

90

130

1

True

Mew

151

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 12 columns

In [190]:

pd.loc['Diglett']

Out[190]:

Num              50

Type 1       Ground

Type 2          NaN

Total           265

HP               10

Attack           55

Defense          25

Sp. Atk          35

Sp. Def          45

Speed            95

Stage             1

Legendary     False

Name: Diglett, dtype: object

In [202]:

pd.loc[['Eevee','Vulpix','Dragonair']]

Out[202]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Eevee

133

Normal

NaN

325

55

55

50

45

65

55

1

False

Vulpix

37

Fire

NaN

299

38

41

40

50

65

65

1

False

Dragonair

148

Dragon

NaN

420

61

84

65

70

70

70

2

False

In [205]:

pd.sort_index().loc['Charizard':'Charmeleon']

Out[205]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Charizard

6

Fire

Flying

534

78

84

78

109

85

100

3

False

Charmander

4

Fire

NaN

309

39

52

43

60

50

65

1

False

Charmeleon

5

Fire

NaN

405

58

64

58

80

65

80

2

False

In [207]:

pd.sort_index().iloc[[30,40,50]]

Out[207]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Eevee

133

Normal

NaN

325

55

55

50

45

65

55

1

False

Gengar

94

Ghost

Poison

500

60

65

60

130

75

110

3

False

Gyarados

130

Water

Flying

540

95

125

79

60

100

81

2

False

In [208]:

fish_pokemon = ['Magikarp','Goldeen','Horsea','Seaking','Seadra','Gyarados']pd.sort_index().loc[fish_pokemon]

Out[208]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Magikarp

129

Water

NaN

200

20

10

55

15

20

80

1

False

Goldeen

118

Water

NaN

320

45

67

60

35

50

63

1

False

Horsea

116

Water

NaN

295

30

40

70

70

25

60

1

False

Seaking

119

Water

NaN

450

80

92

65

65

80

68

2

False

Seadra

117

Water

NaN

440

55

65

95

95

45

85

2

False

Gyarados

130

Water

Flying

540

95

125

79

60

100

81

2

False

In [213]:

water = pd.sort_index().loc[fish_pokemon]df = water.sort_values('Attack')

In [31]:

df

Out[31]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

0

1

Bulbasaur

Grass

Poison

318

45

49

49

65

65

45

1

False

1

2

Ivysaur

Grass

Poison

405

60

62

63

80

80

60

2

False

2

3

Venusaur

Grass

Poison

525

80

82

83

100

100

80

3

False

3

4

Charmander

Fire

NaN

309

39

52

43

60

50

65

1

False

4

5

Charmeleon

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

146

147

Dratini

Dragon

NaN

300

41

64

45

50

50

50

1

False

147

148

Dragonair

Dragon

NaN

420

61

84

65

70

70

70

2

False

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

150

151

Mew

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 13 columns

In [32]:

pok_attack = df[['Attack']]pok_attack

Out[32]:

 

Attack

0

49

1

62

2

82

3

52

4

64

...

...

146

64

147

84

148

134

149

110

150

100

151 rows × 1 columns

In [235]:

pok_attack.plot(kind = 'bar', color = 'purple')

Out[235]:

<Axes: xlabel='Name'>

 

In [17]:

import pandas as pd

In [21]:

df = pd.read_csv('pokemon.csv')df

Out[21]:

 

Num

Name

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

0

1

Bulbasaur

Grass

Poison

318

45

49

49

65

65

45

1

False

1

2

Ivysaur

Grass

Poison

405

60

62

63

80

80

60

2

False

2

3

Venusaur

Grass

Poison

525

80

82

83

100

100

80

3

False

3

4

Charmander

Fire

NaN

309

39

52

43

60

50

65

1

False

4

5

Charmeleon

Fire

NaN

405

58

64

58

80

65

80

2

False

...

...

...

...

...

...

...

...

...

...

...

...

...

...

146

147

Dratini

Dragon

NaN

300

41

64

45

50

50

50

1

False

147

148

Dragonair

Dragon

NaN

420

61

84

65

70

70

70

2

False

148

149

Dragonite

Dragon

Flying

600

91

134

95

100

100

80

3

False

149

150

Mewtwo

Psychic

NaN

680

106

110

90

154

90

130

1

True

150

151

Mew

Psychic

NaN

600

100

100

100

100

100

100

1

False

151 rows × 13 columns

In [25]:

pok_att = df.set_index('Name').sort_values('Attack',ascending = False).head(10)pok_att

Out[25]:

 

Num

Type 1

Type 2

Total

HP

Attack

Defense

Sp. Atk

Sp. Def

Speed

Stage

Legendary

Name

 

 

 

 

 

 

 

 

 

 

 

 

Dragonite

149

Dragon

Flying

600

91

134

95

100

100

80

3

False

Rhydon

112

Ground

Rock

485

105

130

120

45

45

40

2

False

Flareon

136

Fire

NaN

525

65

130

60

95

110

65

2

False

Machamp

68

Fighting

NaN

505

90

130

80

65

85

55

3

False

Kingler

99

Water

NaN

475

55

130

115

50

50

75

2

False

Pinsir

127

Bug

NaN

500

65

125

100

55

70

85

1

False

Gyarados

130

Water

Flying

540

95

125

79

60

100

81

2

False

Hitmonlee

106

Fighting

NaN

455

50

120

53

35

110

87

1

False

Golem

76

Rock

Ground

495

80

120

130

55

65

45

3

False

Kabutops

141

Rock

Water

495

60

115

105

65

70

80

2

False

In [30]:

pok_att[['Attack']].describe()

Out[30]:

 

Attack

count

10.000000

mean

125.900000

std

5.989806

min

115.000000

25%

121.250000

50%

127.500000

75%

130.000000

max

134.000000

In [ ]: